package com.zyh.service.impl;

import com.zyh.core.Page;
import com.zyh.dao.IStudentDao;
import com.zyh.domain.Student;
import com.zyh.service.IStudentService;

import java.sql.SQLException;
import java.util.Collections;
import java.util.List;


public class StudentServiceImpl implements IStudentService {

    private final IStudentDao studentDao;

    public StudentServiceImpl(IStudentDao studentDao) {
        this.studentDao = studentDao;
    }

    @Override
    public List<Student> getStudents(Student student) throws SQLException {
        // 编写业务逻辑
        return studentDao.list(student);
    }

    @Override
    public int addStudent(Student student) throws SQLException {
        return this.studentDao.addStudent(student);
    }

    @Override
    public int deleteStudent(int id) throws SQLException {
        return this.studentDao.deleteStudent(id);
    }

    @Override
    public int updateStudent(Student student) throws SQLException {
        return this.studentDao.updateStudent(student);
    }

    @Override
    public Student getStudent(int id) throws SQLException {
        return this.studentDao.getStudent(id);
    }

    @Override
    public Page<Student> getStudentPage(int pageNum, int pageSize, Student student) throws SQLException {
        int total = this.studentDao.count(student);
        List<Student> students = this.studentDao.page(student,pageNum,pageSize);
        return new Page<Student>(total,students);
    }
}
